package edu.umn.actvs;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.Spinner;

public class SearchActivity extends Activity {
	 /** Called when the activity is first created. */

	Button searchbtn;
	EditText namebox;
	EditText zipbox;
	Spinner hourSpinner;
	Spinner minuteSpinner;
	Spinner periodSpinner;
	Spinner expHourSpinner;
	Spinner expMinuteSpinner;
	Spinner expPeriodSpinner;
	//DatePicker creationbox;
	//DatePicker expirationbox;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.new_search);
        searchbtn = (Button) findViewById(R.id.searchbtn);
        namebox = (EditText) findViewById(R.id.namebox);
        zipbox = (EditText) findViewById(R.id.zipbox);
        
        //creationbox =(DatePicker) findViewById(R.id.createbox);
        //expirationbox =(DatePicker) findViewById(R.id.expbox);
        
        searchbtn.setOnClickListener(new SearchClick());
        
        //takes care of the time dropdowns
        hourSpinner = (Spinner) findViewById(R.id.hour_pick);
        ArrayAdapter hourAdapter = ArrayAdapter.createFromResource(
                this, R.array.hours, android.R.layout.simple_spinner_item);
        hourAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        hourSpinner.setAdapter(hourAdapter);
        
        minuteSpinner = (Spinner) findViewById(R.id.min_pick);
        ArrayAdapter minuteAdapter = ArrayAdapter.createFromResource(
                this, R.array.mins, android.R.layout.simple_spinner_item);
        minuteAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        minuteSpinner.setAdapter(minuteAdapter);
        
        periodSpinner = (Spinner) findViewById(R.id.per_pick);
        ArrayAdapter periodAdapter = ArrayAdapter.createFromResource(
                this, R.array.period, android.R.layout.simple_spinner_item);
        minuteAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        periodSpinner.setAdapter(periodAdapter);
        
        expHourSpinner = (Spinner) findViewById(R.id.exp_hour_pick);
        ArrayAdapter expHourAdapter = ArrayAdapter.createFromResource(
                this, R.array.hours, android.R.layout.simple_spinner_item);
        hourAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        expHourSpinner.setAdapter(expHourAdapter);
        
        expMinuteSpinner = (Spinner) findViewById(R.id.exp_min_pick);
        ArrayAdapter expMinuteAdapter = ArrayAdapter.createFromResource(
                this, R.array.mins, android.R.layout.simple_spinner_item);
        minuteAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        expMinuteSpinner.setAdapter(expMinuteAdapter);
        
        expPeriodSpinner = (Spinner) findViewById(R.id.exp_pick);
        ArrayAdapter expPeriodAdapter = ArrayAdapter.createFromResource(
                this, R.array.period, android.R.layout.simple_spinner_item);
        minuteAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        expPeriodSpinner.setAdapter(expPeriodAdapter);


    }
    
    //this class defines the onclick behaviour
    private class SearchClick implements Button.OnClickListener{

		@Override
		public void onClick(View arg0) {
			// TODO Auto-generated method stub
			String[] query = {};
			query[0] = namebox.getText().toString();
			query[1] = zipbox.getText().toString();
			query[2] = String.valueOf(hourSpinner.getSelectedItem());
			query[3] = String.valueOf(minuteSpinner.getSelectedItem());
			query[4] = String.valueOf(periodSpinner.getSelectedItem());
			query[5] = String.valueOf(expHourSpinner.getSelectedItem());
			query[6] = String.valueOf(expMinuteSpinner.getSelectedItem());
			query[7] = String.valueOf(expPeriodSpinner.getSelectedItem());
			//query[2] = String.valueOf(creationbox.getDayOfMonth());
			//query[3] = String.valueOf(creationbox.getMonth());			
			//query[4] = String.valueOf(expirationbox.getDayOfMonth());
			//query[5] = String.valueOf(expirationbox.getMonth());
		}
    	
    }
}